NETCDF = /public/software/netcdf-3.6.3-pgi/
LIBNETCDF = -L${NETCDF}/lib -lnetcdf -lm
INCLUDE = -I${NETCDF}/include  -I./
FC = pgf90
FCFLAGS = -fast -C -Mfree
#FCFLAGS =-g -byteswapio -Mfree #-q64

CC=gcc
DEFS= -DF90 -DFORTRANUNDERSCORE -DDYNAMIC
CCFLAGS= $(DEFS) # -q64
DBCFLAGS= -g -DDEBUG=1 $(DEFS)

EXENAME = wrf2micaps.exe
OBJS = module_map_utils.o module_wrf_global_attr.o module_wrf_var_nameinfo.o module_wrf_getvar.o \
       general_util.o xy2latlon.o cacul_time_util.o read_namelist_util.o wrf_netcdf_util.o 
AR = ar 
ARFLAGS= cru
#NMFLAGS=-X 64
RANLIB   = ranlib
LIB_NAME = wrfpost
       
RM = rm -f
.SUFFIXES: .F .c .o

all: micaps grads 

micaps:  c_lib module_wrf_micaps_util.o wrf2micaps.o
	$(FC) $(FCFLAGS) -o $(EXENAME) module_wrf_micaps_util.o wrf2micaps.o \
              -L./ -l$(LIB_NAME) $(LIBNETCDF) $(INCLUDE) 
	(cd ../micaps; rm -f wrf2micaps.exe; ln -sf ../src/wrf2micaps.exe .) 
grads:  c_lib create_grads.o wrf2grads.o
	$(FC) $(FCFLAGS) -o wrf2grads.exe create_grads.o wrf2grads.o \
              -L./ -l$(LIB_NAME) $(LIBNETCDF) $(INCLUDE) 
	(cd ../grads; rm -f wrf2grads.exe; ln -sf ../src/wrf2grads.exe .) 
addmicaps:  addmicaps.o
	$(FC) $(FCFLAGS) -o addmicaps addmicaps.o 

c_lib:  $(OBJS) 
	$(AR) $(ARFLAGS) lib$(LIB_NAME).a $(OBJS) 
	$(RANLIB) lib$(LIB_NAME).a
clean:
	$(RM) *.o *.mod *.exe *.a addmicaps  ../micaps/*.exe ../grads/*.exe
.F.o:
	$(RM) $@
	$(FC) -c $(FCFLAGS) $*.F $(INCLUDE)
.c.o:
	$(RM) $@
	$(CC) -c $(CCFLAGS) $*.c $(INCLUDE)

